<?php 
session_start( );
require_once('connections/mysqlDB.php');
$dbConn = new mysqli(HOST,USER,PWD,DB);

/* prepare statement */
$dbConn->query("SET NAMES 'utf8'");
//printf("action= %s, rid= %d, reginfoid= %d<br>", $_POST['action'], $_POST['rid'], $_POST['reginfoid']);

if ($_POST['action'] == "Update") {
  if ($stmt = $dbConn->prepare("UPDATE registration_info SET cname=?, first_name=?, last_name=?,
      relationship=?, gender=?, groups=?, pastoral_staff=?, meal1=?, meal2=?, meal3=?, meal4=?,
      meal5=?, meal6=?, meal7=?, meal8=? WHERE reginfoid=?")) {
    $stmt->bind_param('sssssiiiiiiiiiii', $_POST['cname'], $_POST['first_name'], $_POST['last_name'], 
      $_POST['relation'], $_POST['gender'], $_POST['group'], $_POST['pastor'], $_POST['meal1'],
      $_POST['meal2'], $_POST['meal3'], $_POST['meal4'], $_POST['meal5'], $_POST['meal6'],
      $_POST['meal7'], $_POST['meal8'], $_POST['reginfoid']);
    $stmt->execute(); 
    printf ("Updated records: %d<br>", $stmt->affected_rows);
  }
}

if ($_POST['action'] == "Del") {
  if ($stmt = $dbConn->prepare("DELETE FROM registration_info WHERE reginfoid= ?")) {
    $stmt->bind_param('i', $_POST['reginfoid']);
    $stmt->execute(); 
    printf ("Deleted records: %d<br>", $stmt->affected_rows);
  }
}

if ($_POST['action'] == "Add") {
    $rid = $_POST['rid'];
    if ($stmt = $dbConn->prepare("INSERT INTO registration_info (rid) VALUES (?)")) {
    $stmt->bind_param('i', $rid);
    $stmt->execute();
    $reginfoid = $stmt->insert_id;
    printf ("Added records: %d, record id: %d<br>", $stmt->affected_rows, $reginfoid);
    }

    if ($stmt = $dbConn->prepare("UPDATE registration_info SET cname=?, first_name=?, last_name=?,
      relationship=?, gender=?, groups=?, pastoral_staff=?, meal1=?, meal2=?, meal3=?, meal4=?,
      meal5=?, meal6=?, meal7=?, meal8=? WHERE reginfoid=?")) {
    $stmt->bind_param('sssssiiiiiiiiiii', $_POST['cname'], $_POST['first_name'], $_POST['last_name'], 
      $_POST['relation'], $_POST['gender'], $_POST['group'], $_POST['pastor'], $_POST['meal1'],
      $_POST['meal2'], $_POST['meal3'], $_POST['meal4'], $_POST['meal5'], $_POST['meal6'],
      $_POST['meal7'], $_POST['meal8'], $reginfoid);
    $stmt->execute();
    printf ("Updated records: %d<br>", $stmt->affected_rows);
    }
}
if ($_POST['action'] == "xAdd") {
    if ($stmt = $dbConn->prepare("INSERT INTO registration_info (rid, cname, first_name, last_name,
      relationship, gender, groups, pastoral_staff, meal1, meal2, meal3, meal4, meal5, meal6,
      meal7, meal8) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")) {
    $stmt->bind_param('isssssiiiiiiiiii', $_POST['rid'], $_POST['cname'], $_POST['first_name'],
      $_POST['last_name'], $_POST['relation'], $_POST['gender'], $_POST['group'], $_POST['pastor'],
      $_POST['meal1'], $_POST['meal2'], $_POST['meal3'], $_POST['meal4'], $_POST['meal5'],
      $_POST['meal6'], $_POST['meal7'], $_POST['meal8']);
    $stmt->execute();
    printf ("Added records: %d<br>", $stmt->affected_rows);
  }
}

$dbConn->close();
?>

<script>
<!--
location.replace("con_registration.php");
-->
</script>
Click <a href=con_registration.php>here</a> to continue...
